package com.android.baseconfig.common.entity;

import android.graphics.Rect;
import android.view.View;

import androidx.recyclerview.widget.RecyclerView;

/**
 * ---------------------------------------------------------------- <br>
 * Copyright (C) 2014-2020, by het, Shenzhen, All rights reserved.  <br>
 * ---------------------------------------------------------------- <br>
 * <p>
 * 描述: CustomItemDecoration <br>
 * 作者: lei <br>
 * 日期: 2021/7/19 <br>
 */
public class IntervalItemDecoration extends RecyclerView.ItemDecoration {
    private int spaceTop;
    private int spaceBottom;
    private int spaceLeft;
    private int spaceRight;
    private boolean isOneNo;

    /**
     * @param spaceTop
     * @param isOneNo     第一个不偏移
     */
    public IntervalItemDecoration(int spaceTop, boolean isOneNo) {
        this.spaceTop = spaceTop;
        this.isOneNo = isOneNo;
    }

    /**
     * @param spaceTop
     * @param spaceBottom
     * @param isOneNo     第一个不偏移
     */
    public IntervalItemDecoration(int spaceTop, int spaceBottom, boolean isOneNo) {
        this.spaceTop = spaceTop;
        this.spaceBottom = spaceBottom;
        this.isOneNo = isOneNo;
    }

    /**
     * @param spaceLeft
     * @param spaceTop
     * @param spaceRight
     * @param spaceBottom
     */
    public IntervalItemDecoration(int spaceLeft, int spaceTop, int spaceRight, int spaceBottom) {
        this.spaceTop = spaceTop;
        this.spaceBottom = spaceBottom;
        this.spaceLeft = spaceLeft;
        this.spaceRight = spaceRight;
    }

    /**
     * @param spaceLeft
     * @param spaceTop
     * @param spaceRight
     * @param spaceBottom
     * @param isOneNo     第一个不偏移
     */
    public IntervalItemDecoration(int spaceLeft, int spaceTop, int spaceRight, int spaceBottom, boolean isOneNo) {
        this.isOneNo = isOneNo;
        this.spaceTop = spaceTop;
        this.spaceBottom = spaceBottom;
        this.spaceLeft = spaceLeft;
        this.spaceRight = spaceRight;
    }

    @Override
    public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) {
        if (isOneNo) {
            if (parent.getChildAdapterPosition(view) != 0) {
                outRect.left = spaceLeft;
                outRect.right = spaceRight;
                outRect.bottom = spaceBottom;
                outRect.top = spaceTop;
            }
        } else {
            outRect.left = spaceLeft;
            outRect.right = spaceRight;
            outRect.bottom = spaceBottom;
            outRect.top = spaceTop;
        }
    }
}
